package xyz.wbsite.dbtool.javafx.po;

import javafx.beans.property.SimpleStringProperty;
import xyz.wbsite.dbtool.javafx.annotation.Property;

import java.util.ArrayList;
import java.util.List;

public class Project {

    public Project() {
        setName("example-web");
        setNote("示例项目");
        setAuthor("author");
        setDomain("com.example");
        this.frame = Frame.基础框架;
        this.database = DataBase.MySQL;
        this.needEMail = false;
    }

    public Project(String name) {
        setName(name);
    }

    @Property("name")
    private SimpleStringProperty name = new SimpleStringProperty();
    @Property("note")
    private SimpleStringProperty note = new SimpleStringProperty();
    @Property("domain")
    private SimpleStringProperty domain = new SimpleStringProperty();
    @Property("author")
    private SimpleStringProperty author = new SimpleStringProperty();
    @Property(value = "frame")
    private Frame frame;
    @Property(value = "database")
    private DataBase database;
    @Property("needMoreDB")
    private boolean needMoreDB;
    @Property("needEMail")
    private boolean needEMail;
    @Property("needAsync")
    private boolean needAsync;

    /**
     * 对象
     */
    private List<Module> modules = new ArrayList();

    public boolean putModule(Module module) {
        modules.add(module);
        return true;
    }

    public String getName() {
        return name.get();
    }

    public SimpleStringProperty nameProperty() {
        return name;
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public String getNote() {
        return note.get();
    }

    public SimpleStringProperty noteProperty() {
        return note;
    }

    public void setNote(String note) {
        this.note.set(note);
    }

    public String getDomain() {
        return domain.get();
    }

    public SimpleStringProperty domainProperty() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain.set(domain);
    }

    public String getAuthor() {
        return author.get();
    }

    public SimpleStringProperty authorProperty() {
        return author;
    }

    public void setAuthor(String author) {
        this.author.set(author);
    }

    public List<Module> getModules() {
        return modules;
    }

    public void setModules(List<Module> modules) {
        this.modules = modules;
    }

    public boolean isNeedMoreDB() {
        return needMoreDB;
    }

    public void setNeedMoreDB(boolean needMoreDB) {
        this.needMoreDB = needMoreDB;
    }

    public DataBase getDatabase() {
        return database;
    }

    public void setDatabase(DataBase database) {
        this.database = database;
    }

    public boolean isNeedEMail() {
        return needEMail;
    }

    public void setNeedEMail(boolean needEMail) {
        this.needEMail = needEMail;
    }

    public boolean isNeedAsync() {
        return needAsync;
    }

    public void setNeedAsync(boolean needAsync) {
        this.needAsync = needAsync;
    }

    public Frame getFrame() {
        return frame;
    }

    public void setFrame(Frame frame) {
        this.frame = frame;
    }

    public int frameValue() {
        return frame.value();
    }

    public boolean isNeedApi() {
        for (Module module : modules) {
            for (Table table : module.getTables()) {
                if (table.getApi()) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isNeedAjax() {
        for (Module module : modules) {
            for (Table table : module.getTables()) {
                if (table.isAjax()) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isNeedHtml() {
        for (Module module : modules) {
            for (Table table : module.getTables()) {
                if (table.isPage()) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isNeedCloud() {
        for (Module module : modules) {
            for (Table table : module.getTables()) {
                if (table.getMsvr()) {
                    return true;
                }
            }
        }
        return false;
    }
}
